$.validator.setDefaults({
    submitHandler: function (val) {
         oktipsoption = {
                type: 1,
                url: $('.formsub').attr('url'),
                msg: '提交成功'
            };
            ajaxform.init(oktipsoption, '.formsub');
            ajaxform.submit();
        //submit('',successcallback('修改成功,请重新登陆',$('.formsub').attr('tipurl')));
    },
    errorPlacement: function (error, element) {
        element.parents('td').append(error);
        element.parents('.l_b').append(error);
        element.parents('.l_b').find('.prompt').hide();
    }
});

$(document).ready(function () {
    // // 退回
    // $(".js_back").click(function () {
    //     layer.open({
    //         title: '<span class="title_s">退回原因</span>',
    //         type: 1,
    //         content: $(".back_box"),
    //         area: ["542px", "362px"]
    //     });
    // });
    
    // 限制只能输入数字
    var record;
    var bank = $(".bank_form");
    bank.on('keyup', '.line_num,.bank_num', function (event) {
        var myThis = $(this);
        var val = myThis.val();
        var decimalReg = /^[1-9][0-9]*$/;
        if (val != '' && decimalReg.test(val)) {
            record = val;
        } else {
            if (val != '') {
                myThis.val(record);
            }
        }
        myThis.blur(function () {
            record = '';
        });
    })

    bank.on('focus', '.table_box input[type=text]', function (event) {
        $(this).addClass('u-ipt-active');
        $(this).removeClass('error');
        $(this).next('label.error').hide();
        $(this).parent('.l_b').find('label.error').hide();
        $(this).parent('.l_b').find('.prompt').show();
    });


    bank.on('blur', '.table_box input[type=text]', function (event) {
        $(this).removeClass('u-ipt-active');
        $("#bank_form").validate().element($(this))
        if ($(this).parent().find('label.error').is(":visible")) {
            $(this).addClass('error');
            $(this).parent('.l_b').find('.prompt').hide();
        } else {
            $(this).removeClass('error');
            $(this).removeClass('u-ipt-active');
            $(this).parent('.l_b').find('.prompt').show();
        }
    });

     $.validator.addMethod("chkbankname", function (value) {
        var yzcodeReg = /^[\u4e00-\u9fa5]+$/;
        return yzcodeReg.test(value);
    });

    var bank_form = $("#bank_form").validate({
        rules: {
            line_num: {
                required: true
            },
            bank_num: {
                required: true,
                minlength:16
            },
            address: {
                required: true
            },
            bank_name: {
                required: true,
                chkbankname:true
            },
            payee: {
                required: true
            }
        },
        messages: {
            line_num: {
                required: '请填写联行号'
            },
            bank_num: {
                required: '请填写收款银行账号',
                minlength:'银行卡号至少为16位'
            },
            address: {
                required: '请填写收款人地址 '
            },
            bank_name: {
                required: '请填写开户行名称 ',
                chkbankname:'开户行名称为中文'
            },
            payee: {
                required: '请填写收款人的姓名'
            }
        },
        focusInvalid: false,
        onkeyup: false
    });
})